package com.utils;

import com.model.ListNode;

import java.util.Objects;

/**
 * 输出内容配置
 */
public class PrintUtils {

    /**
     * 二维数组输出
     * @param queue 二维数组 {{1,2}, {2,3}, {3,4}}
     * @return 输出内容: [[1,2], [2,3], [3,4]]
     */
    public static String structQueue(int[][] queue) {
        StringBuilder result = new StringBuilder("[");

        if (queue.length < 1) {
            return "[]";
        }

        for (int[] nums : queue) {
            result.append(" [").append(nums[0]).append(",").append(nums[1]).append("],");
        }

        return result.toString().substring(0, result.length() - 1) + " ]";
    }

    /**
     * 链表输出
     * @param listNode 链表 1->2->3
     * @return 输出内容: 1->2->3
     */
    public static String structListNode(ListNode listNode) {
        StringBuilder result = new StringBuilder(listNode.val.toString());

        ListNode next = listNode.next;
        while (next != null) {
            result.append("->").append(next.val.toString());
            next = next.next;
        }

        return result.toString();
    }
}
